


import matplotlib.pyplot as plt
import numpy as np
import time
import tensorflow as tf
import cv2

def unpickle(file_path):
    import pickle
    with open(file_path,'rb') as fo:
        dict = pickle.load(fo,encoding = 'bytes')
    return dict
data_path = []

def data_load():
    data_totle = []
    labels = []
    labels_name = []
    for i in range(5):
        k = i + 1
        data_path.append('E:\\文件\\vision\\cifar-10-batches-py\\data_batch_' + str(k))
        data_batch = unpickle(data_path[-1])
        key = data_batch.keys()
       
        value = list(data_batch.values())
        
        images = value[2]
        data_totle += list(images)
        labels += value[1]
        labels_name += value[3]
    return np.array(data_totle),np.array(labels),np.array(labels_name)

images,labels,labels_name = data_load()
print(images.shape)  #50000,3072
print(images.dtype)

def cv_image(x):
    cv_img = []
    for i in range(len(x)):
        img = x.reshape([-1,3,32,32])
        a = img[i][0]
        b = img[i][1]
        c = img[i][2]
        f = cv2.merge([a,b,c])
        cv_img.append(list(f))
    return np.array(cv_img)
        
v = cv_image(images)
cv2.imshow('f',v[3])
cv2.waitKey(0)
       